package com.ywgt.controller;

import com.github.pagehelper.Page;
import com.ywgt.pojo.Feedback;
import com.ywgt.service.FeedbackService;
import com.ywgt.util.ResponseUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/admin/feedback")
@ApiModel("意见反馈管理")
public class FeedbackController {

    @Autowired
    FeedbackService feedbackService;

    /**
     * page: 1,
     * limit: 20,
     * username: undefined,
     * sort: 'add_time',
     * order: 'desc'
     * @return
     */
    @GetMapping("/list")
    public Object getFeedbacks(String username, @RequestParam(required = false,defaultValue = "1") int page,
                               @RequestParam(required = false,defaultValue = "10") int limit,
                               @RequestParam(required = false,defaultValue = "add_time") String sort,
                               @RequestParam(required = false,defaultValue = "desc") String order){
    Page<Feedback> feedbacks=feedbackService.getFeedbacks(username,page,limit,sort,order);
        List<Feedback> items = feedbacks.getResult();
        long total = feedbacks.getTotal();
        Map<String,Object> data=new HashMap<>();
        data.put("total",total);
        data.put("items",items);
        return ResponseUtil.ok(data);
    }
}
